package com.situ.crm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.crm.common.ServerResponse;
import com.situ.crm.entity.Permission;
import com.situ.crm.service.IPermissionService;

@Controller
@RequestMapping(value="/permission")
public class PermissionController {
	@Autowired
	private IPermissionService permissionService;
	
	@RequestMapping(value="/getPermissionPage")
	public String getPermissionPage() {
		return "permission/permission_list";
	}
	
	@RequestMapping(value="/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page,Integer limit,Permission permission) {
		ServerResponse serverResponse = permissionService.pageList(page,limit,permission);
		return serverResponse;
	}
	
	//添加页面
	@RequestMapping(value="/getAddPage")
	public String getAddPage() {
		return "permission/permission_insert";
	}
	
	//添加功能
	@RequestMapping(value="/insert")
	@ResponseBody
	public ServerResponse insert(Permission permission) {
		return permissionService.insert(permission);
	}
	
	//删除功能
	@RequestMapping(value="/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return permissionService.deleteById(id);
	}
	
	//批量删除
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids) {
		return permissionService.deleteAll(ids);
	}
	
	//修改页面
	@RequestMapping(value="/getUpdatePage")
	public String getUpdatePage(Integer id,Model model) {
		Permission permission = permissionService.selectId(id);
		model.addAttribute("permission",permission);
		return "permission/permission_update";
	}
	
	//修改功能
	@RequestMapping(value="/update")
	@ResponseBody
	public ServerResponse update(Permission permission) {
		return permissionService.update(permission);
	}
	
	//角色添加查询权限
	@RequestMapping(value="/selectAllPermission")
	@ResponseBody
	public ServerResponse selectAllPermission() {
		return permissionService.selectAllPermission();
	}
}
